<template>
  <el-tabs type="border-card" v-model="activeName">
    <el-tab-pane label="布防时间" name="first">
      <timeChoose ref="timeChoose" :initialSchedule="schedule"></timeChoose>
      <el-button class="!mt-8 block" type="primary" @click="save" style="margin-left: 0px; width: 120px">保存</el-button>

    </el-tab-pane>
    <el-tab-pane label="联动方式" name="s">
      <para></para>
    </el-tab-pane>
  </el-tabs>
</template>
<script>
import para from "@/views/mini/temperature-management/liandongfangshi.vue"
import timeChoose from '@/views/components/time.vue';
import {
  getAlarmArmingConfig,
  getNormalAlarmInConfig,
  getNormalAlarmSchedule,
  postAlarmArmingConfig,
  postSnapshotSchedule
} from "@/api/api2";

export default {
  components: {
    para,
    timeChoose
  },
  data() {
    return {
      activeName: 'first',
      schedule: [
        // {
        //   "dayOfWeek": "Monday",
        //   "action":[
        //     {
        //       "id": 1,
        //       "startTime": "15:30:00",
        //       "endTime": "16:30:00",
        //     }
        //   ]
        // },
        // {
        //   "dayOfWeek": "Tuesday",
        //   "action":[
        //     {
        //       "id": 1,
        //       "startTime": "15:30:00",
        //       "endTime": "16:30:00",
        //     }
        //   ]
        // }
      ],
    };
  },
  created() {
    getAlarmArmingConfig().then(res => {
      if (res.code === 0) {
        this.schedule = res.data.daySchedules;
      } else {
        this.$message.error("获取配置失败");
      }
    })
  },
  methods: {
    save(tab, event) {
      let form = this.$refs.timeChoose.form.scheduleAction;
      postAlarmArmingConfig({
        type: 'thermal',
        daySchedules: form
      }).then(res => {
        if (res.code === 0) {
          this.$message({
            message: '保存成功',
            type: 'success'
          });
        } else {
          this.$message({
            message: '保存失败',
            type: 'error'
          });
        }
      })
    }
  }
};
</script>
